/*
 * @Description: -
 * @Author: sanghx
 * @Date: 2019-11-02 16:01:21
 * @LastEditors: sanghx
 * @LastEditTime: 2019-11-05 16:30:53
 */
import { map } from '@/api/dictionary'
const Dictionary = {
  _map: '',
  getMap () {
    map().then(res => {
      if (res.status === 200) {
        this._map = res.result
      } else {
        console.log(res.message)
      }
    })
  },
  getVLList (em) {
    let res = []
    if (this._map.hasOwnProperty(em)) {
      const list = this._map[em]
      list.forEach(item => {
        res.push({
          value: item.enumValue,
          label: item.name
        })
      })
    }
    return res
  },
  getName (em, value) {
    let res = value
    if (this._map.hasOwnProperty(em)) {
      const list = this._map[em]
      list.forEach(item => {
        if (item.enumValue === value) {
          res = item.name
        }
      })
    }
    return res
  },
  install (Vue, options) {
    this.getMap()
    Vue.prototype.$dn = this.getName.bind(this) // 获取字典名称
    Vue.prototype.$dv = this.getVLList.bind(this) // 获取指定枚举字典集
    // this.$dv('sex')
    // this.$dn('sex', '0')
  }
}

export default Dictionary
